/**
	@file bootloader.S
	@author Andrew D. Zonenberg
	@brief Just a jumping point for the main function
 */


.set noreorder					/*	Prevent any optimizations from reordering instructions!
									We want exe to exactly match source! */

/*
	Program entry point
 */
.section .startup.bootvec, "ax", @progbits 
.globl _start
_start:
	/* TODO: copy initialized data from the end of the ROM image into RAM */
	
	/*	Make sure we have a valid stack pointer. Just stick it near the end of ram for now.
		Current RAM is
			a000:0000 to a000:0fff (uncached) and
			8000:0000 to 8000:0fff (cached).
		Both refer to the same physical address range.		
		*/
	lui		$sp, 0x8000
	addiu	$sp, 0x0ffc
	
	/*	get address of main function in kseg1 by subtracting 0x2000:0000*/
	la		$k0, main
	lui		$k1, 0x2000
	subu	$k0, $k0, $k1
	
	/* Call the main function */
	jalr	$k0
	nop
	
	/* should never get here, but if we do, infinite loop */
.infloop:
	j		.infloop

	/* padding */
	nop
	nop
	nop
	nop

/*
	CP0 timer function
 */
.section .startup
.global cp0_timer_init
cp0_timer_init:
	mtc0	$zero, $9		/* start counting now */
	jr		$ra
	nop
	nop

.section .startup
.global cp0_timer_value
cp0_timer_value:
	mfc0	$v0, $9
	jr		$ra
	nop
	nop
